package com.atguigu.spzx.cart.controller;

import com.atguigu.spzx.cart.service.CartService;
import com.atguigu.spzx.model.entity.h5.CartItem;
import com.atguigu.spzx.model.vo.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "购物车模块")
@RequestMapping("/api/order/cart")
public class CartController {
    @Resource
    CartService cartService;
    @Operation(summary = "删除用户已选中的购物项接口")
    @DeleteMapping("/auth/deleteCartItems")
    public Result deleteCartItems(){
        cartService.deleteCartItems();
        return Result.ok();
    }
    @Operation(summary = "查询用户已选中的购物项列表接口")
    @GetMapping("/auth/findCheckedCartItems")
    public Result findCheckedCartItems(){
        List<CartItem> checkedItems = cartService.findCheckedCartItems();
        return Result.ok().data(checkedItems);
    }
    @Operation(summary = "删除购物项接口")
    @DeleteMapping("/auth/deleteCart/{skuId}")
    public Result deleteCart(@PathVariable("skuId")Long skuId){
        cartService.deleteCart(skuId);
        return Result.ok();
    }
    @Operation(summary = "更新购物项选中状态")
    @GetMapping("/auth/checkCart/{skuId}/{status}")
    public Result checkCart(@PathVariable("skuId")Long skuId ,
                            @PathVariable("status") Integer status){
        cartService.checkCart(skuId,status);
        return Result.ok();
    }
    @Operation(summary = "更新所有购物项选中态接口")
    @GetMapping("/auth/allCheckCart/{status}")
    public Result allCheckCart(@PathVariable("status") Integer status){
        cartService.allCheckCart(status);
        return Result.ok();
    }
    @Operation(summary = "添加商品到购物车接口")
    @GetMapping("/auth/addToCart/{skuId}/{skuNum}")
    public Result add2Cart(@PathVariable("skuId")Long skuId ,
                           @PathVariable("skuNum") Integer skuNum){
        cartService.add2Cart(skuId , skuNum);
        return Result.ok();
    }
    ///api/order/cart/auth/cartList
    @Operation(summary = "查询购物车购物项列表接口")
    @GetMapping("/auth/cartList")
    public Result cartList(){
       List<CartItem> cartItemList = cartService.cartList();
       return Result.ok().data(cartItemList);
    }
    @Operation(summary = "清空购物车接口")
    @GetMapping("/auth/clearCart")
    public Result clearCart(){
        cartService.clearCart();
        return Result.ok();
    }
}
